package com.treasure.mall.biz.service.core.module.impl;

import com.treasure.mall.biz.entity.module.ModulePO;
import com.treasure.mall.biz.mapstruct.ModuleMapStruct;
import com.treasure.mall.biz.repository.module.ModuleRepository;
import com.treasure.mall.biz.service.core.module.ModuleService;
import com.treasure.mall.biz.vo.module.ModuleVO;
import com.treasure.mall.zbq.common.ienum.banner.ModuleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * <p>
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.service.core.module.impl
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/8/10 10:05 上午
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * 
 */
@Service
public class ModuleServiceImpl implements ModuleService {

    @Autowired
    private ModuleRepository moduleRepository;


    @Override
    public ModulePO findById(Long Id) {
        return moduleRepository.findById(Id).orElse(null);
    }

    @Override
    public ModuleVO getConfig(ModuleType moduleType) {
        ModulePO po = moduleRepository.findFirstByModuleType(moduleType);
        if (po != null) {
            return ModuleMapStruct.INSTANCE.po2vo(po);
        }
        return new ModuleVO();

    }

    @Override
    public List<ModuleVO> findAll() {
        List<ModulePO> list = moduleRepository.findAll();
        if (list != null) {
            return ModuleMapStruct.INSTANCE.pos2vos(list);
        }
        return null;
    }


    @Override
    public ModuleVO save(ModulePO po) {
        po = moduleRepository.save(po);
        return ModuleMapStruct.INSTANCE.po2vo(po);
    }
}
